package com.itxx.test.Demo1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

//服务器端(接收端)
public class TcpRecevie {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(34567);
        //监听(等待)客户端Socket对象连接
        Socket accept = ss.accept();
        //创建字符缓冲输入流
        BufferedReader br = new BufferedReader(new InputStreamReader(accept.getInputStream()));
        //读取数据
        String s = br.readLine();
        System.out.println("这是接受的数据:" + s);

        //释放资源
        ss.close();
        accept.close();


        /*try (ServerSocket ss = new ServerSocket(34567);
             //监听(等待)客户端Socket对象连接
             Socket accept = ss.accept();
             //创建字符缓冲输入流
             BufferedReader br = new BufferedReader(new InputStreamReader(accept.getInputStream()));
             ) {
            //读取数据
            String s = br.readLine();
            System.out.println("这是接受的数据:" + s);
        }
*/

    }
}
